From 0fdaf507a1f9dd9f6eb59e5579c6cf6f2cd9cff2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 19 Jan 2015 14:27:51 -0800 Subject: [PATCH] Remove infrastructure for the old custom build command This aspect of the manifest has been deprecated for quite some time now, and this commit purges the support entirely. --- src/cargo/core/manifest.rs | 10 - src/cargo/ops/cargo_rustc/custom_build.rs | 2 +- src/cargo/ops/cargo_rustc/fingerprint.rs | 13 +- src/cargo/ops/cargo_rustc/mod.rs | 143 +------ src/cargo/util/toml.rs | 32 +- tests/test_cargo_bench.rs | 3 +- tests/test_cargo_compile.rs | 31 +- tests/test_cargo_compile_git_deps.rs | 17 +- tests/test_cargo_compile_old_custom_build.rs | 408 ------------------- tests/test_cargo_compile_path_deps.rs | 9 +- tests/test_cargo_cross_compile.rs | 25 +- tests/test_cargo_doc.rs | 3 +- tests/test_cargo_test.rs | 3 +- tests/tests.rs | 1 - 14 files changed, 57 insertions(+), 643 deletions(-) delete mode 100644 tests/test_cargo_compile_old_custom_build.rs diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 836919de5..e45dfe219 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -15,7 +15,6 @@ pub struct Manifest { targets: Vec, target_dir: Path, doc_dir: Path, - build: Vec, // TODO: deprecated, remove links: Option, warnings: Vec, exclude: Vec, @@ -52,7 +51,6 @@ pub struct SerializedManifest { targets: Vec, target_dir: String, doc_dir: String, - build: Option>, // TODO: deprecated, remove } impl Encodable for Manifest { @@ -66,8 +64,6 @@ impl Encodable for Manifest { targets: self.targets.clone(), target_dir: self.target_dir.display().to_string(), doc_dir: self.doc_dir.display().to_string(), - // TODO: deprecated, remove - build: if self.build.len() == 0 { None } else { Some(self.build.clone()) }, }.encode(s) } } @@ -388,7 +384,6 @@ impl Encodable for Target { impl Manifest { pub fn new(summary: Summary, targets: Vec, target_dir: Path, doc_dir: Path, - build: Vec, exclude: Vec, include: Vec, links: Option, @@ -398,7 +393,6 @@ impl Manifest { targets: targets, target_dir: target_dir, doc_dir: doc_dir, - build: build, // TODO: deprecated, remove warnings: Vec::new(), exclude: exclude, include: include, @@ -439,10 +433,6 @@ impl Manifest { &self.doc_dir } - pub fn get_build(&self) -> &[String] { - self.build.as_slice() - } - pub fn get_links(&self) -> Option<&str> { self.links.as_ref().map(|s| s.as_slice()) } diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs index 72560226a..54b633d58 100644 --- a/src/cargo/ops/cargo_rustc/custom_build.rs +++ b/src/cargo/ops/cargo_rustc/custom_build.rs @@ -179,7 +179,7 @@ pub fn prepare(pkg: &Package, target: &Target, req: Platform, // // Also note that a fresh build command needs to let (freshness, dirty, fresh) = - try!(fingerprint::prepare_build_cmd(cx, pkg, Some(target))); + try!(fingerprint::prepare_build_cmd(cx, pkg, kind, Some(target))); let dirty = Work::new(move |tx| { try!(work(tx.clone())); dirty.call(tx) diff --git a/src/cargo/ops/cargo_rustc/fingerprint.rs b/src/cargo/ops/cargo_rustc/fingerprint.rs index a70767965..7f765a354 100644 --- a/src/cargo/ops/cargo_rustc/fingerprint.rs +++ b/src/cargo/ops/cargo_rustc/fingerprint.rs @@ -124,17 +124,14 @@ pub fn prepare_target(cx: &mut Context, pkg: &Package, target: &Target, /// /// The currently implemented solution is option (1), although it is planned to /// migrate to option (2) in the near future. -pub fn prepare_build_cmd(cx: &mut Context, pkg: &Package, +pub fn prepare_build_cmd(cx: &mut Context, pkg: &Package, kind: Kind, target: Option<&Target>) -> CargoResult { - let _p = profile::start(format!("fingerprint build cmd: {}", - pkg.get_package_id())); - - // TODO: this should not explicitly pass Kind::Target - let kind = Kind::Target; - - if pkg.get_manifest().get_build().len() == 0 && target.is_none() { + if target.is_none() { return Ok((Fresh, Work::noop(), Work::noop())); } + + let _p = profile::start(format!("fingerprint build cmd: {}", + pkg.get_package_id())); let new = dir(cx, pkg, kind); let loc = new.join("build"); cx.layout(pkg, kind).proxy().whitelist(&loc); diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index a61fddb36..a5d563398 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -1,14 +1,12 @@ use std::collections::{HashSet, HashMap}; use std::dynamic_lib::DynamicLibrary; -use std::ffi::CString; -use std::io::USER_RWX; use std::io::fs::{self, PathExtensions}; use std::path; use std::sync::Arc; use core::{SourceMap, Package, PackageId, PackageSet, Target, Resolve}; use util::{self, CargoResult, human, caused_human}; -use util::{Config, internal, ChainError, Fresh, profile, join_paths, Human}; +use util::{Config, internal, ChainError, Fresh, profile, join_paths}; use self::job::{Job, Work}; use self::job_queue::{JobQueue, Stage}; @@ -320,39 +318,8 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package, } } - if targets.iter().any(|t| t.get_profile().is_custom_build()) { - // New custom build system - jobs.enqueue(pkg, Stage::BuildCustomBuild, build_custom); - jobs.enqueue(pkg, Stage::RunCustomBuild, run_custom); - - } else { - // Old custom build system - // OLD-BUILD: to-remove - let mut build_cmds = Vec::new(); - for (i, build_cmd) in pkg.get_manifest().get_build().iter().enumerate() { - let work = try!(compile_custom_old(pkg, build_cmd.as_slice(), cx, i == 0)); - build_cmds.push(work); - } - let (freshness, dirty, fresh) = - try!(fingerprint::prepare_build_cmd(cx, pkg, None)); - let desc = match build_cmds.len() { - 0 => String::new(), - 1 => pkg.get_manifest().get_build()[0].to_string(), - _ => format!("custom build commands"), - }; - let dirty = Work::new(move |desc_tx| { - if desc.len() > 0 { - desc_tx.send(desc).ok(); - } - for cmd in build_cmds.into_iter() { - try!(cmd.call(desc_tx.clone())) - } - dirty.call(desc_tx) - }); - jobs.enqueue(pkg, Stage::BuildCustomBuild, vec![]); - jobs.enqueue(pkg, Stage::RunCustomBuild, vec![(job(dirty, fresh), freshness)]); - } - + jobs.enqueue(pkg, Stage::BuildCustomBuild, build_custom); + jobs.enqueue(pkg, Stage::RunCustomBuild, run_custom); jobs.enqueue(pkg, Stage::Libraries, libs); jobs.enqueue(pkg, Stage::Binaries, bins); jobs.enqueue(pkg, Stage::BinaryTests, bin_tests); @@ -360,81 +327,6 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package, Ok(()) } -// OLD-BUILD: to-remove -fn compile_custom_old(pkg: &Package, cmd: &str, - cx: &Context, first: bool) -> CargoResult { - let root = cx.get_package(cx.resolve.root()); - let profile = root.get_manifest().get_targets().iter() - .find(|target| target.get_profile().get_env() == cx.env()) - .map(|target| target.get_profile()); - let profile = match profile { - Some(profile) => profile, - None => return Err(internal(format!("no profile for {}", cx.env()))) - }; - // Just need a target which isn't a custom build command - let target = &pkg.get_targets()[0]; - assert!(!target.get_profile().is_custom_build()); - - // TODO: this needs to be smarter about splitting - let mut cmd = cmd.split(' '); - // TODO: this shouldn't explicitly pass `Kind::Target` for dest/deps_dir, we - // may be building a C lib for a plugin - let layout = cx.layout(pkg, Kind::Target); - let output = layout.native(pkg); - let exe = CString::from_slice(cmd.next().unwrap().as_bytes()); - let mut p = try!(process(CommandType::Host(exe), pkg, target, cx)) - .env("OUT_DIR", Some(&output)) - .env("DEPS_DIR", Some(&output)) - .env("TARGET", Some(cx.target_triple())) - .env("DEBUG", Some(profile.get_debug().to_string())) - .env("OPT_LEVEL", Some(profile.get_opt_level().to_string())) - .env("LTO", Some(profile.get_lto().to_string())) - .env("PROFILE", Some(profile.get_env())); - for arg in cmd { - p = p.arg(arg); - } - match cx.resolve.features(pkg.get_package_id()) { - Some(features) => { - for feat in features.iter() { - p = p.env(format!("CARGO_FEATURE_{}", - envify(feat.as_slice())).as_slice(), - Some("1")); - } - } - None => {} - } - - - for &(pkg, _) in cx.dep_targets(pkg, target).iter() { - let name: String = pkg.get_name().chars().map(|c| { - match c { - '-' => '_', - c => c.to_uppercase(), - } - }).collect(); - p = p.env(format!("DEP_{}_OUT_DIR", name).as_slice(), - Some(&layout.native(pkg))); - } - let pkg = pkg.to_string(); - - let exec_engine = cx.exec_engine.clone(); - - Ok(Work::new(move |desc_tx| { - desc_tx.send(p.to_string()).ok(); - if first && !output.exists() { - try!(fs::mkdir(&output, USER_RWX).chain_error(|| { - internal("failed to create output directory for build command") - })) - } - try!(exec_engine.exec_with_output(p).map(|_| ()).map_err(|mut e| { - e.desc = format!("Failed to run custom build command for `{}`\n{}", - pkg, e.desc); - Human(e) - })); - Ok(()) - })) -} - fn rustc(package: &Package, target: &Target, cx: &mut Context, req: Platform) -> CargoResult >{ @@ -766,19 +658,6 @@ fn build_deps_args(mut cmd: CommandPrototype, target: &Target, package: &Package None }); - // Traverse the entire dependency graph looking for -L paths to pass for - // native dependencies. - // OLD-BUILD: to-remove - let mut dirs = Vec::new(); - each_dep(package, cx, |pkg| { - if pkg.get_manifest().get_build().len() > 0 { - dirs.push(layout.native(pkg)); - } - }); - for dir in dirs.into_iter() { - cmd = cmd.arg("-L").arg(format!("native={}", dir.display())); - } - for &(pkg, target) in cx.dep_targets(package, target).iter() { cmd = try!(link_to(cmd, pkg, target, cx, kind)); } @@ -821,7 +700,7 @@ fn build_deps_args(mut cmd: CommandPrototype, target: &Target, package: &Package } } -pub fn process(cmd: CommandType, pkg: &Package, target: &Target, +pub fn process(cmd: CommandType, pkg: &Package, _target: &Target, cx: &Context) -> CargoResult { // When invoking a tool, we need the *host* deps directory in the dynamic // library search path for plugins and such which have dynamic dependencies. @@ -829,20 +708,6 @@ pub fn process(cmd: CommandType, pkg: &Package, target: &Target, let mut search_path = DynamicLibrary::search_path(); search_path.push(layout.deps().clone()); - // OLD-BUILD: to-remove - // Also be sure to pick up any native build directories required by plugins - // or their dependencies - let mut native_search_paths = HashSet::new(); - for &(dep, target) in cx.dep_targets(pkg, target).iter() { - if !target.get_profile().is_for_host() { continue } - each_dep(dep, cx, |dep| { - if dep.get_manifest().get_build().len() > 0 { - native_search_paths.insert(layout.native(dep)); - } - }); - } - search_path.extend(native_search_paths.into_iter()); - // We want to use the same environment and such as normal processes, but we // want to override the dylib search path with the one we just calculated. let search_path = try!(join_paths(search_path.as_slice(), diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index ca072252b..9e51f09c8 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -253,7 +253,7 @@ pub struct TomlProject { name: String, version: TomlVersion, authors: Vec, - build: Option, // TODO: `String` instead + build: Option, links: Option, exclude: Option>, include: Option>, @@ -269,13 +269,6 @@ pub struct TomlProject { repository: Option, } -// TODO: deprecated, remove -#[derive(RustcDecodable)] -pub enum BuildCommand { - Single(String), - Multiple(Vec) -} - pub struct TomlVersion { version: semver::Version, } @@ -449,17 +442,7 @@ impl TomlManifest { }; // processing the custom build script - let (new_build, old_build) = match project.build { - Some(BuildCommand::Single(ref cmd)) => { - if cmd.as_slice().ends_with(".rs") && layout.root.join(cmd.as_slice()).exists() { - (Some(Path::new(cmd.as_slice())), Vec::new()) - } else { - (None, vec!(cmd.clone())) - } - }, - Some(BuildCommand::Multiple(ref cmd)) => (None, cmd.clone()), - None => (None, Vec::new()) - }; + let new_build = project.build.clone().map(Path::new); // Get targets let profiles = self.profile.clone().unwrap_or(Default::default()); @@ -509,8 +492,6 @@ impl TomlManifest { let exclude = project.exclude.clone().unwrap_or(Vec::new()); let include = project.include.clone().unwrap_or(Vec::new()); - let has_old_build = old_build.len() >= 1; - let summary = try!(Summary::new(pkgid, deps, self.features.clone() .unwrap_or(HashMap::new()))); @@ -529,7 +510,6 @@ impl TomlManifest { targets, layout.root.join("target"), layout.root.join("doc"), - old_build, exclude, include, project.links.clone(), @@ -538,14 +518,6 @@ impl TomlManifest { manifest.add_warning(format!("the [[lib]] section has been \ deprecated in favor of [lib]")); } - if has_old_build { - manifest.add_warning(format!("warning: an arbitrary build command \ - has now been deprecated.")); - manifest.add_warning(format!(" It has been replaced by custom \ - build scripts.")); - manifest.add_warning(format!(" For more information, see \ - http://doc.crates.io/build-script.html")); - } if project.license_file.is_some() && project.license.is_some() { manifest.add_warning(format!("warning: only one of `license` or \ `license-file` is necessary")); diff --git a/tests/test_cargo_bench.rs b/tests/test_cargo_bench.rs index 70c75fdd1..3108b0bc2 100644 --- a/tests/test_cargo_bench.rs +++ b/tests/test_cargo_bench.rs @@ -750,8 +750,9 @@ test!(bench_twice_with_build_cmd { name = "foo" version = "0.0.1" authors = [] - build = 'true' + build = "build.rs" "#) + .file("build.rs", "fn main() {}") .file("src/lib.rs", " extern crate test; #[bench] diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 6b08da08f..43e7343c0 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -1252,9 +1252,10 @@ test!(freshness_ignores_excluded { name = "foo" version = "0.0.0" authors = [] - build = "true" + build = "build.rs" exclude = ["src/b*.rs"] "#) + .file("build.rs", "fn main() {}") .file("src/lib.rs", "pub fn bar() -> int { 1 }"); foo.build(); foo.root().move_into_the_past().unwrap(); @@ -1280,37 +1281,27 @@ test!(freshness_ignores_excluded { }); test!(rebuild_preserves_out_dir { - let mut build = project("builder"); - build = build + let foo = project("foo") .file("Cargo.toml", r#" [package] - name = "builder" - version = "0.5.0" - authors = ["wycats@example.com"] + name = "foo" + version = "0.0.0" + authors = [] + build = 'build.rs' "#) - .file("src/main.rs", r#" + .file("build.rs", r#" use std::os; use std::io::File; - fn main() {{ + fn main() { let path = Path::new(os::getenv("OUT_DIR").unwrap()).join("foo"); if os::getenv("FIRST").is_some() { File::create(&path).unwrap(); } else { File::create(&path).unwrap(); } - }} - "#); - assert_that(build.cargo_process("build"), execs().with_status(0)); - - let foo = project("foo") - .file("Cargo.toml", format!(r#" - [package] - name = "foo" - version = "0.0.0" - authors = [] - build = '{}' - "#, build.bin("builder").display()).as_slice()) + } + "#) .file("src/lib.rs", "pub fn bar() -> int { 1 }"); foo.build(); foo.root().move_into_the_past().unwrap(); diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index 422f43990..7555c94a8 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -1087,8 +1087,9 @@ test!(git_build_cmd_freshness { name = "foo" version = "0.0.0" authors = [] - build = "true" + build = "build.rs" "#) + .file("build.rs", "fn main() {}") .file("src/lib.rs", "pub fn bar() -> int { 1 }") .file(".gitignore", " src/bar.rs @@ -1175,11 +1176,12 @@ test!(git_repo_changing_no_rebuild { name = "p1" version = "0.5.0" authors = [] - build = 'true' + build = 'build.rs' [dependencies.bar] git = '{}' "#, bar.url()).as_slice()) - .file("src/main.rs", "fn main() {}"); + .file("src/main.rs", "fn main() {}") + .file("build.rs", "fn main() {}"); p1.build(); p1.root().move_into_the_past().unwrap(); assert_that(p1.process(cargo_dir().join("cargo")).arg("build"), @@ -1247,7 +1249,7 @@ test!(git_dep_build_cmd { name = "bar" version = "0.5.0" authors = ["wycats@example.com"] - build = "cp src/bar.rs.in src/bar.rs" + build = "build.rs" [lib] @@ -1256,6 +1258,13 @@ test!(git_dep_build_cmd { .file("bar/src/bar.rs.in", r#" pub fn gimme() -> int { 0 } "#) + .file("bar/build.rs", r#" + use std::io::fs; + fn main() { + fs::copy(&Path::new("src/bar.rs.in"), + &Path::new("src/bar.rs")).unwrap(); + } + "#) }).unwrap(); p.root().join("bar").move_into_the_past().unwrap(); diff --git a/tests/test_cargo_compile_old_custom_build.rs b/tests/test_cargo_compile_old_custom_build.rs deleted file mode 100644 index 0855548d3..000000000 --- a/tests/test_cargo_compile_old_custom_build.rs +++ /dev/null @@ -1,408 +0,0 @@ -use std::path; - -use support::{project, execs, cargo_dir}; -use hamcrest::{assert_that}; - -fn setup() { -} - -test!(old_custom_build { - let mut build = project("builder"); - build = build - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] name = "foo" - "#) - .file("src/foo.rs", r#" - fn main() { println!("Hello!"); } - "#); - assert_that(build.cargo_process("build"), - execs().with_status(0)); - - - let mut p = project("foo"); - p = p - .file("Cargo.toml", format!(r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - build = '{}' - - [[bin]] name = "foo" - "#, build.bin("foo").display())) - .file("src/foo.rs", r#" - fn main() {} - "#); - assert_that(p.cargo_process("build"), - execs().with_status(0) - .with_stdout(format!(" Compiling foo v0.5.0 ({})\n", - p.url())) - .with_stderr("warning: [..] deprecated.\n\ - [..]\n\ - [..]")); -}); - -test!(old_custom_multiple_build { - let mut build1 = project("builder1"); - build1 = build1 - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] name = "foo" - "#) - .file("src/foo.rs", r#" - fn main() { - let args = ::std::os::args(); - assert_eq!(args[1], "hello".to_string()); - assert_eq!(args[2], "world".to_string()); - } - "#); - assert_that(build1.cargo_process("build"), - execs().with_status(0)); - - let mut build2 = project("builder2"); - build2 = build2 - .file("Cargo.toml", r#" - [project] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] name = "bar" - "#) - .file("src/bar.rs", r#" - fn main() { - let args = ::std::os::args(); - assert_eq!(args[1], "cargo".to_string()); - } - "#); - assert_that(build2.cargo_process("build"), - execs().with_status(0)); - - let mut p = project("foo"); - p = p - .file("Cargo.toml", format!(r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - build = [ '{} hello world', '{} cargo' ] - - [[bin]] name = "foo" - "#, build1.bin("foo").display(), build2.bin("bar").display())) - .file("src/foo.rs", r#" - fn main() {} - "#); - assert_that(p.cargo_process("build"), - execs().with_status(0) - .with_stdout(format!(" Compiling foo v0.5.0 ({})\n", - p.url()))); -}); - -test!(old_custom_build_failure { - let mut build = project("builder"); - build = build - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] - name = "foo" - "#) - .file("src/foo.rs", r#" - fn main() { panic!("nope") } - "#); - assert_that(build.cargo_process("build"), execs().with_status(0)); - - - let mut p = project("foo"); - p = p - .file("Cargo.toml", format!(r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - build = '{}' - - [[bin]] - name = "foo" - "#, build.bin("foo").display())) - .file("src/foo.rs", r#" - fn main() {} - "#); - assert_that(p.cargo_process("build"), - execs().with_status(101).with_stderr(format!("\ -warning: an arbitrary build command has now been deprecated. - [..] - [..] -Failed to run custom build command for `foo v0.5.0 ({dir})` -Process didn't exit successfully: `{}` (status=101)\n\ ---- stderr\n\ -thread '
' panicked at 'nope', {filename}:2\n\ -\n\ -", build.bin("foo").display(), filename = format!("src{}foo.rs", path::SEP), - dir = p.url()))); -}); - -test!(old_custom_second_build_failure { - let mut build1 = project("builder1"); - build1 = build1 - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] name = "foo" - "#) - .file("src/foo.rs", r#" - fn main() { println!("Hello!"); } - "#); - assert_that(build1.cargo_process("build"), - execs().with_status(0)); - - let mut build2 = project("builder2"); - build2 = build2 - .file("Cargo.toml", r#" - [project] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] - name = "bar" - "#) - .file("src/bar.rs", r#" - fn main() { panic!("nope") } - "#); - assert_that(build2.cargo_process("build"), execs().with_status(0)); - - - let mut p = project("foo"); - p = p - .file("Cargo.toml", format!(r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - build = [ '{}', '{}' ] - - [[bin]] - name = "foo" - "#, build1.bin("foo").display(), build2.bin("bar").display())) - .file("src/foo.rs", r#" - fn main() {} - "#); - assert_that(p.cargo_process("build"), - execs().with_status(101).with_stderr(format!("\ -warning: an arbitrary build command has now been deprecated. - [..] - [..] -Failed to run custom build command for `foo v0.5.0 ({dir})` -Process didn't exit successfully: `{}` (status=101)\n\ ---- stderr\n\ -thread '
' panicked at 'nope', {filename}:2\n\ -\n\ -", build2.bin("bar").display(), filename = format!("src{}bar.rs", path::SEP), - dir = p.url()))); -}); - -test!(old_custom_build_env_vars { - let bar = project("bar") - .file("Cargo.toml", r#" - [package] - name = "bar-bar" - version = "0.0.1" - authors = [] - build = "true" - "#) - .file("src/lib.rs", ""); - bar.build(); - - let mut p = project("foo"); - let mut build = project("builder"); - build = build - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [features] - foo = [] - - [[bin]] - name = "foo" - "#) - .file("src/foo.rs", format!(r#" - use std::os; - use std::io::fs::PathExtensions; - fn main() {{ - let _ncpus = os::getenv("NUM_JOBS").unwrap(); - let _feat = os::getenv("CARGO_FEATURE_FOO").unwrap(); - let debug = os::getenv("DEBUG").unwrap(); - assert_eq!(debug.as_slice(), "true"); - - let opt = os::getenv("OPT_LEVEL").unwrap(); - assert_eq!(opt.as_slice(), "0"); - - let opt = os::getenv("PROFILE").unwrap(); - assert_eq!(opt.as_slice(), "compile"); - - let out = os::getenv("OUT_DIR").unwrap(); - assert!(out.as_slice().starts_with(r"{0}")); - assert!(Path::new(out).is_dir()); - - let out = os::getenv("DEP_BAR_BAR_OUT_DIR").unwrap(); - assert!(out.as_slice().starts_with(r"{0}")); - assert!(Path::new(out).is_dir()); - - let out = os::getenv("CARGO_MANIFEST_DIR").unwrap(); - let p1 = Path::new(out); - let p2 = os::make_absolute(&Path::new(file!()).dir_path().dir_path()).unwrap(); - assert!(p1 == p2, "{{}} != {{}}", p1.display(), p2.display()); - }} - "#, - p.root().join("target").join("native").display())); - assert_that(build.cargo_process("build").arg("--features").arg("foo"), - execs().with_status(0)); - - - p = p - .file("Cargo.toml", format!(r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - build = '{}' - - [features] - foo = [] - - [[bin]] - name = "foo" - - [dependencies.bar-bar] - path = '{}' - "#, build.bin("foo").display(), bar.root().display())) - .file("src/foo.rs", r#" - fn main() {} - "#); - assert_that(p.cargo_process("build").arg("--features").arg("foo"), - execs().with_status(0)); -}); - -test!(old_custom_build_in_dependency { - let mut p = project("foo"); - let mut build = project("builder"); - build = build - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] - name = "foo" - "#) - .file("src/foo.rs", format!(r#" - use std::os; - fn main() {{ - assert!(os::getenv("OUT_DIR").unwrap().as_slice() - .starts_with(r"{}")); - }} - "#, - p.root().join("target/native/bar-").display())); - assert_that(build.cargo_process("build"), execs().with_status(0)); - - - p = p - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] - name = "foo" - [dependencies.bar] - path = "bar" - "#) - .file("src/foo.rs", r#" - extern crate bar; - fn main() { bar::bar() } - "#) - .file("bar/Cargo.toml", format!(r#" - [project] - - name = "bar" - version = "0.5.0" - authors = ["wycats@example.com"] - build = '{}' - "#, build.bin("foo").display())) - .file("bar/src/lib.rs", r#" - pub fn bar() {} - "#); - assert_that(p.cargo_process("build"), - execs().with_status(0)); -}); - -// tests that custom build in dep can be built twice in a row - issue 227 -test!(old_custom_build_in_dependency_twice { - let p = project("foo") - .file("Cargo.toml", r#" - [project] - - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - - [[bin]] - name = "foo" - [dependencies.bar] - path = "./bar" - "#) - .file("src/foo.rs", r#" - extern crate bar; - fn main() { bar::bar() } - "#) - .file("bar/Cargo.toml", format!(r#" - [project] - - name = "bar" - version = "0.0.1" - authors = ["wycats@example.com"] - build = '{}' - "#, "echo test")) - .file("bar/src/lib.rs", r#" - pub fn bar() {} - "#); - assert_that(p.cargo_process("build"), - execs().with_status(0)); - assert_that(p.process(cargo_dir().join("cargo")).arg("build"), - execs().with_status(0)); -}); diff --git a/tests/test_cargo_compile_path_deps.rs b/tests/test_cargo_compile_path_deps.rs index 3e6a75294..7ca80b5dd 100644 --- a/tests/test_cargo_compile_path_deps.rs +++ b/tests/test_cargo_compile_path_deps.rs @@ -658,12 +658,19 @@ test!(path_dep_build_cmd { name = "bar" version = "0.5.0" authors = ["wycats@example.com"] - build = "cp src/bar.rs.in src/bar.rs" + build = "build.rs" [lib] name = "bar" "#) + .file("bar/build.rs", r#" + use std::io::fs; + fn main() { + fs::copy(&Path::new("src/bar.rs.in"), + &Path::new("src/bar.rs")).unwrap(); + } + "#) .file("bar/src/bar.rs.in", r#" pub fn gimme() -> int { 0 } "#); diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index 668a81ab6..a4d2ed024 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -34,30 +34,19 @@ fn alternate() -> &'static str { test!(simple_cross { if disabled() { return } - let mut build = project("builder"); - build = build + let p = project("foo") .file("Cargo.toml", r#" - [project] + [package] name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] + version = "0.0.0" + authors = [] + build = "build.rs" "#) - .file("src/main.rs", format!(r#" + .file("build.rs", format!(r#" fn main() {{ assert_eq!(std::os::getenv("TARGET").unwrap().as_slice(), "{}"); }} - "#, alternate()).as_slice()); - assert_that(build.cargo_process("build"), - execs().with_status(0)); - - let p = project("foo") - .file("Cargo.toml", format!(r#" - [package] - name = "foo" - version = "0.0.0" - authors = [] - build = '{}' - "#, build.bin("foo").display())) + "#, alternate()).as_slice()) .file("src/main.rs", r#" use std::os; fn main() { diff --git a/tests/test_cargo_doc.rs b/tests/test_cargo_doc.rs index e26f46ebf..3612b0312 100644 --- a/tests/test_cargo_doc.rs +++ b/tests/test_cargo_doc.rs @@ -12,8 +12,9 @@ test!(simple { name = "foo" version = "0.0.1" authors = [] - build = 'true' + build = "build.rs" "#) + .file("build.rs", "fn main() {}") .file("src/lib.rs", r#" pub fn foo() {} "#); diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 877454357..f9478626f 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -755,8 +755,9 @@ test!(test_twice_with_build_cmd { name = "foo" version = "0.0.1" authors = [] - build = 'true' + build = "build.rs" "#) + .file("build.rs", "fn main() {}") .file("src/lib.rs", " #[test] fn foo() {} diff --git a/tests/tests.rs b/tests/tests.rs index 96a4049ae..c4e5f356d 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -34,7 +34,6 @@ mod test_cargo_clean; mod test_cargo_compile; mod test_cargo_compile_custom_build; mod test_cargo_compile_git_deps; -mod test_cargo_compile_old_custom_build; mod test_cargo_compile_path_deps; mod test_cargo_compile_plugins; mod test_cargo_cross_compile; -- 2.30.2